package acm.pta12;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] a = new int[201][201];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int s = sc.nextInt();
            a[x][y] = s;
            a[y][x] = s;
        }
        int num = sc.nextInt();
        int cost;
        int mincost = Integer.MAX_VALUE;
        int sn = 0;
        int glnum = 0;
        for (int i = 0; i < num; i++) {
            int p = sc.nextInt();
            cost = 0;
            int cur = 0;
            int[] arr = new int[201];
            int flag = 0;
            int k = 0;
            for (int j = 0; j < p; j++) {
                k = sc.nextInt();
                if (a[cur][k] != 0 && arr[k] == 0) {
                    cost += a[cur][k];
                    arr[k] = 1;
                    cur = k;
                } else {
                    flag = 1;
                }
            }
            cost += a[k][0];
            if (p == n && a[k][0] != 0 && flag == 0) {
                if (cost < mincost) {
                    mincost = cost;
                    sn = i + 1;
                }
                glnum++;
            }
        }
        System.out.println(glnum + "\n" + sn + ' ' + mincost);
    }
    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }
        public void clear(){
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}
